<?php


trait Trait_Api_Payqrcode
{



    /**
     * 创建订单基础数据
     * @param $params
     * @param $line_info
     * @param $suit_info
     * @param $member_info
     * @return array
     * @throws Exception
     */
    public function make_order_data($params, $info, $member_info)
    {
        // 联系人信息
        $linkman   = trim(Arr::get($params, 'linkman'));
        $linktel   = trim(Arr::get($params, 'linktel'));
        $linkemail = Arr::get($params, 'linkemail');

        // 备注信息
        $remark = Arr::get($params, 'remark', '');


        // 订单编号
        $ordersn = Product::get_ordersn(self::TYPE_ID);

        // 订单数据
        $data = array(
            'typeid' => self::TYPE_ID,
            'webid' => 0,
            'ordersn' => $ordersn,
            'productautoid' => $info['id'],
            'litpic' => '',
            'productaid' => 0,
            'productname' => $info['title'],
            'departdate' => '0',
            'jifenbook' => 0,
            'suitid' => 0,
            'need_confirm' => 0,
            'suit_name' => $info['title'],
            'refund_restriction' => 0,
            'needjifen' => 0,
            'usejifen' => 0,
            'jifentprice' => 0,
            'jifencomment' => 0,
            'memberid' => $member_info['mid'],
            'linkman' => $linkman,
            'linktel' => $linktel,
            'linkemail' => $linkemail,
            'remark' => $remark,
            'addtime' => time(),
        );

        //成人数量
        $data['dingnum'] = 1;

        //出发日期
        $data['usedate'] = '';
        // 订单来源 1PC,2WAP,3小程序,4平台添加
        $data['source'] = Arr::get($params, 'source', 3);
        // 自动关闭订单时间
        $data['auto_close_time'] = strtotime('+ 20 minute');
        return $data;
    }


    /**
     * 格式化价格
     * @param array $price_arr
     * @return array
     */
    public static function format_order_price($price_arr)
    {
        $price_key = array(
            'adultprice',
            'childprice',
            'oldprice',
            'people4_price',
            'people5_price',
            'people6_price',
            'roombalance'
        );

        foreach ($price_arr as $key => &$value) {
            if (in_array($key, $price_key)) {
                $value = Currency_Tool::price($value);
                $value = doubleval($value);
            }
        }
        return $price_arr;
    }


}